package com.my12306.train.controller;

import com.my12306.common.model.vo.PageVo;
import com.my12306.common.util.PageUtils;
import com.my12306.common.util.response.ResponseData;
import com.my12306.train.model.entity.TrainEntity;
import com.my12306.train.model.vo.TrainVo;
import com.my12306.train.service.TrainService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Arrays;
import java.util.Date;
import java.util.List;
import java.util.Map;

/**
 * 列车表
 *
 * @author ËÕÄÁÏ¦
 * @email
 * @date 2020-07-24 20:58:07
 */
@RestController
@RequestMapping("/train")
public class TrainController {
    @Autowired
    private TrainService trainService;

    /**
     * 列表
     */
    @PostMapping("/list")
    public ResponseData list(@RequestBody PageVo pageVo) {
        PageUtils page = trainService.queryTrainPage(pageVo);
        return ResponseData.ok().put("page", page);
    }

    /**
     * 信息
     */
    @GetMapping("/info/{trainId}")
    public ResponseData info(@PathVariable("trainId") Long trainId) {
        TrainEntity train = trainService.getById(trainId);
        return ResponseData.ok().put("train", train);
    }

    /**
     * 保存
     */
    @PostMapping("/save")
    public ResponseData save(@RequestBody TrainEntity train) {
        trainService.saveTrain(train);
        return ResponseData.ok();
    }

    /**
     * 修改
     */
    @PutMapping("/update")
    public ResponseData update(@RequestBody TrainVo train) {
        trainService.updateTrainById(train);
        return ResponseData.ok();
    }

    /**
     * 删除
     */
    @DeleteMapping("/delete")
    public ResponseData delete(@RequestBody List<Long> trainIds) {
        System.out.println(trainIds);
        trainService.deleteTrainBatchByIds(trainIds);
        return ResponseData.ok();
    }

}
